﻿#region using

using System;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;

#endregion using

namespace T4_Eind_programma
{
    public partial class HistorieScherm : Form
    {
        #region Variable Declaration

        private BindingList<Order> orderList;

        #endregion Variable Declaration

        #region Constructor

        public HistorieScherm(BindingList<Order> orderList)
        {
            InitializeComponent();
            this.orderList = orderList;
            VulListViewMetOrderList(orderList);
        }

        #endregion Constructor

        private void ListViewItemDoubleClicked(object sender, System.EventArgs e)
        {
            Mengbatch mengbatch = orderList[listBatch.SelectedItems[0].Index].MengbatchList.Where
                (mengbatchItem => mengbatchItem.Nummer == Convert.ToInt32(listBatch.SelectedItems[0].Text)).Single();
            VulbatchScherm mijnHistorieVulBatch = new VulbatchScherm(mengbatch);
            mijnHistorieVulBatch.Closing += new System.ComponentModel.CancelEventHandler(OnSearchClosingVulbatch);
            this.Enabled = false;
            mijnHistorieVulBatch.Show();
        }

        private void OnSearchClosingVulbatch(object sender, System.ComponentModel.CancelEventArgs e)
        {
            this.Enabled = true;
        }

        private void VulListViewMetOrderList(BindingList<Order> orderList)
        {
            foreach (Order order in orderList)
            {
                foreach (Mengbatch batch in order.MengbatchList)
                {
                    if (batch.Klaar == true)
                    {
                        ListViewItem lv = new ListViewItem(order.Nummer.ToString());
                        lv.SubItems.Add(batch.Nummer.ToString());
                        lv.SubItems.Add(batch.Productcode.ToString());
                        lv.SubItems.Add(batch.Smaak.Naam);
                        lv.SubItems.Add(batch.Hoeveelheid.ToString());
                        lv.SubItems.Add(batch.SiroopPercentage.ToString());
                        lv.SubItems.Add(batch.Mengtijd.ToString());
                        lv.SubItems.Add(batch.Verwarmen.ToString());
                        lv.SubItems.Add(batch.Handmatig.ToString());
                        lv.SubItems.Add(batch.Doeltank.ToString());
                        lv.SubItems.Add(batch.Klaar.ToString());
                        listBatch.Items.Add(lv);
                    }
                }
            }
        }
    }
}